package CinemaDevelop;

import java.util.Arrays;

public class SeatingChart {
    private int row;
    private int line;
    private String[][] matrix;
    private int seatNum;

    public SeatingChart() {
    }

    public SeatingChart(int row, int line) {
        this.row = row;
        this.line = line;
        seatNum = row * line;
        matrix = new String[row][line];
        for (String[] array : matrix) {
            Arrays.fill(array, "空");
        }
    }

    public void add(int row, int line, String information) {
        if (matrix[row-1][line-1].equals("空")) {
            matrix[row-1][line-1] = information;
            System.out.println("出票成功！ " + row + "行" + line + "列 观影人信息：" + information);
        } else {
            System.out.println("出票失败！此位置有人。");
        }
    }

    public void subtract(int row, int line) {
        if (matrix[row-1][line-1].equals("空")) {
            System.out.println("此座位无人，退票失败！");
        } else {
            matrix[row-1][line-1] = "空";
            System.out.println("退票成功！");
        }
    }

    public void check(int row, int line) {
        if (matrix[row-1][line-1].equals("空")) {
            System.out.println("此座位为空！");
        } else {
            System.out.println("此座位有人！观影人：" + matrix[row-1][line-1]);
        }
    }

    public void isEmpty() {
        for (int i = 0; i < row; i++) {
            for (int j = 0; j < line; j++) {
                if (matrix[i][j].equals("空")) {
                    System.out.println((i+1) + "行" + (j+1) + "列");
                }
            }
        }
    }

    public void seatingInformation() {
        System.out.print("   ");
        for (int i = 0; i < line; i++) {
            System.out.print(String.format("%2d ", i+1));
        }
        System.out.println();

        for (int i = 0; i < row; i++) {
            System.out.print(String.format("%2d", i+1));
            for (int j = 0; j < line; j++) {
                if (matrix[i][j].equals("空")) {
                    System.out.print("  O");
                } else {
                    System.out.print("  x");
                }
            }
            System.out.println();
        }
    }

    public int getRow() {
        return row;
    }

    public int getSeatNum() {
        return seatNum;
    }

    public int getLine() {
        return line;
    }
}








